'use strict';
const Service = require('egg').Service;
const PDFMerge = require('pdf-merge');

class Merge extends Service{
	async create(data){
        const ctx = this.ctx;
        const base_url = 'http://192.168.0.96:7001';
        let files = data.source.split('|').map(item=>{
            return base_url+item
        });
        try {
            let fileName = ctx.helper.generateSecret(10);
            PDFMerge(files, {output: './app/public/pdf/'+ data.date + fileName +'.pdf'}).then((buffer) => {});
            return ctx.helper.success({url:'/public/pdf/'+ data.date + fileName +'.pdf'},"成功");
        } catch (e) {
            return ctx.helper.fail('异常');
        }
	}
}
module.exports = Merge;